AmCharts.AmExport=AmCharts.Class({construct:function(e,t,i){var o=this;o.DEBUG=false;o.chart=e;o.canvas=null;o.svgs=[];o.userCFG=t;o.buttonIcon="export.png";o.exportPNG=true;o.exportPDF=false;o.exportJPG=false;o.exportSVG=false;o.right=0;o.top=0;o.buttonRollOverColor="#EFEFEF";o.textRollOverColor="#CC0000";o.buttonTitle="Save chart as an image";o.buttonAlpha=.75;o.imageFileName="amChart";o.imageBackgroundColor="#FFFFFF";if(i){o.init()}},toCoordinate:function(e){if(e===undefined){return"auto"}if(String(e).indexOf("%")!=-1){return e}else{return e+"px"}},init:function(){var e=this;var t=[];if(e.exportPNG){t.push("png")}if(e.exportPDF){t.push("pdf")}if(e.exportJPG){t.push("jpg")}if(e.exportSVG){t.push("svg")}var i=[];if(t.length==1){var o=t[0];i.push({format:o,iconTitle:e.buttonTitle,icon:e.chart.pathToImages+e.buttonIcon})}else if(t.length>1){var r=[];for(var n=0;n<t.length;n++){r.push({format:t[n],title:t[n].toUpperCase()})}i.push({onclick:function(){},icon:e.chart.pathToImages+e.buttonIcon,items:r})}var a=e.color;if(a===undefined){a=e.chart.color}var l=e.buttonColor;if(l===undefined){l="transparent"}e.cfg={menuTop:e.toCoordinate(e.top),menuLeft:e.toCoordinate(e.left),menuRight:e.toCoordinate(e.right),menuBottom:e.toCoordinate(e.bottom),menuItems:i,menuItemStyle:{backgroundColor:l,opacity:e.buttonAlpha,rollOverBackgroundColor:e.buttonRollOverColor,color:a,rollOverColor:e.textRollOverColor,paddingTop:"6px",paddingRight:"6px",paddingBottom:"6px",paddingLeft:"6px",marginTop:"0px",marginRight:"0px",marginBottom:"0px",marginLeft:"0px",textAlign:"left",textDecoration:"none",fontFamily:e.chart.fontFamily,fontSize:e.chart.fontSize+"px"},menuItemOutput:{backgroundColor:e.imageBackgroundColor,fileName:e.imageFileName,format:"png",output:"dataurlnewwindow",render:"browser",dpi:90,onclick:function(e,t,i){i.preventDefault();e.output(t)}},removeImagery:true};e.processing={buffer:[],drawn:0,timer:0};if(typeof window.canvg!="undefined"&&typeof window.RGBColor!="undefined"){e.cfg.menuItemOutput.render="canvg"}if(typeof window.saveAs!="undefined"){e.cfg.menuItemOutput.output="save"}if(AmCharts.isIE&&AmCharts.IEversion<10){e.cfg.menuItemOutput.output="dataurlnewwindow"}var s=e.userCFG;if(s){s.menuItemOutput=AmCharts.extend(e.cfg.menuItemOutput,s.menuItemOutput||{});s.menuItemStyle=AmCharts.extend(e.cfg.menuItemStyle,s.menuItemStyle||{});e.cfg=AmCharts.extend(e.cfg,s)}e.chart.AmExport=e;e.chart.addListener("rendered",function(){e.setup()});if(e.DEBUG){window.AmExport=e}},log:function(){console.log("AmExport: ",arguments)},setup:function(){var e=this;if(e.DEBUG==10){e.log("SETUP START")}if(!AmCharts.isIE||AmCharts.isIE&&AmCharts.IEversion>9){e.generateButtons();if(e.DEBUG==10){e.log("SETUP END")}}else{if(e.DEBUG==10){e.log("< IE10 NOT SUPPORTED")}}},generateBinaryArray:function(e){var t=e.length,i=new Uint8Array(t/4*3|0),o=0,r=0,n=[0,0],a=0,l=0,s,g,u,f=new Uint8Array([62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,0,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51]);while(t--){g=e.charCodeAt(o++);s=f[g-43];if(s!==255&&s!==u){n[1]=n[0];n[0]=g;l=l<<6|s;a++;if(a===4){i[r++]=l>>>16;if(n[1]!==61){i[r++]=l>>>8}if(n[0]!==61){i[r++]=l}a=0}}}return i},generateBlob:function(e,t){var i=this,o=t!="image/svg+xml"?e.indexOf(",")+1:0,r=e.substring(0,o),n=e,a=new Blob;if(r.indexOf("base64")!=-1){n=i.generateBinaryArray(e.substring(o))}if(AmCharts.isIE&&AmCharts.IEversion<10){a.data=n;a.size=n.length;a.type=t;a.encoding="base64"}else{a=new Blob([n],{type:t})}return a},generatePDF:function(e){var t=this,i={output:function(){return""}},o=t.canvas.toDataURL("image/jpeg"),r=t.canvas.width*25.4/e.dpi,n=t.canvas.height*25.4/e.dpi;if(window.jsPDF){i=new jsPDF;if(i.addImage){i.addImage(o,"JPEG",0,0,r,n)}else{alert("Missing jsPDF plugin; Please add the 'addImage' plugin.")}}else{alert("Missing jsPDF lib; Don't forget to add the addImage plugin.")}return i},output:function(e,t){var i=this;e=AmCharts.extend(AmCharts.extend({},i.cfg.menuItemOutput),e||{});if(i.chart.prepareForExport){i.chart.prepareForExport()}function o(){var o=null;var r;if(i.DEBUG==10){i.log("OUTPUT",e.format)}if(e.format=="image/svg+xml"||e.format=="svg"){o=i.generateSVG();r=i.generateBlob(o,"image/svg+xml");if(e.output=="save"){saveAs(r,e.fileName+".svg")}else if(e.output=="datastring"||e.output=="datauristring"||e.output=="dataurlstring"){r="data:image/svg+xml;base64,"+btoa(o)}else if(e.output=="dataurlnewwindow"){window.open("data:image/svg+xml;base64,"+btoa(o))}else if(e.output=="datauri"||e.output=="dataurl"){location.href="data:image/svg+xml;base64,"+btoa(o)}else if(e.output=="datastream"){location.href="data:image/octet-stream;base64,"+o}if(t)t.apply(i,[r])}else if(e.format=="application/pdf"||e.format=="pdf"){o=i.generatePDF(e).output("dataurlstring");r=i.generateBlob(o,"application/pdf");if(e.output=="save"){saveAs(r,e.fileName+".pdf")}else if(e.output=="datastring"||e.output=="datauristring"||e.output=="dataurlstring"){r=o}else if(e.output=="dataurlnewwindow"){window.open(o)}else if(e.output=="datauri"||e.output=="dataurl"){location.href=o}else if(e.output=="datastream"){location.href=o.replace("application/pdf","application/octet-stream")}if(t)t.apply(i,[r])}else if(e.format=="image/png"||e.format=="png"){o=i.canvas.toDataURL("image/png");r=i.generateBlob(o,"image/png");if(e.output=="save"){saveAs(r,e.fileName+".png")}else if(e.output=="datastring"||e.output=="datauristring"||e.output=="dataurlstring"){r=o}else if(e.output=="dataurlnewwindow"){window.open(o)}else if(e.output=="datauri"||e.output=="dataurl"){location.href=o}else if(e.output=="datastream"){location.href=o.replace("image/png","image/octet-stream")}if(t)t.apply(i,[r])}else if(e.format=="image/jpeg"||e.format=="jpeg"||e.format=="jpg"){o=i.canvas.toDataURL("image/jpeg");r=i.generateBlob(o,"image/jpeg");if(e.output=="save"){saveAs(r,e.fileName+".jpg")}else if(e.output=="datastring"||e.output=="datauristring"||e.output=="dataurlstring"){r=o}else if(e.output=="dataurlnewwindow"){window.open(o)}else if(e.output=="datauri"||e.output=="dataurl"){location.href=o}else if(e.output=="datastream"){location.href=o.replace("image/jpeg","image/octet-stream")}if(t)t.apply(i,[r])}}return i.generateOutput(e,o)},polifySVG:function(e){var t=this;function i(e,i){var o=e.getElementsByTagName(i);var r=o.length;while(r--){if(t.cfg.removeImagery){o[r].parentNode.removeChild(o[r])}else{var n=document.createElement("img");var a=document.createElement("canvas");var l=a.getContext("2d");a.width=o[r].getAttribute("width");a.height=o[r].getAttribute("height");n.src=o[r].getAttribute("xlink:href");n.width=o[r].getAttribute("width");n.height=o[r].getAttribute("height");try{l.drawImage(n,0,0,n.width,n.height);datastring=a.toDataURL()}catch(s){datastring=n.src;t.log("Tainted canvas, reached browser CORS security; origin from imagery must be equal to the server!");throw new Error(s)}o[r].setAttribute("xlink:href",datastring)}if(t.DEBUG==10){t.log("POLIFIED",o[r])}}}if(AmCharts.IEversion==0){e.setAttribute("xmlns","http://www.w3.org/2000/svg");if(!t.cfg.removeImagery){e.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink")}}if(t.DEBUG==10){t.log("POLIFIED",e)}i(e,"pattern");i(e,"image");t.svgs.push(e);return e},generateSVG:function(){var e=this;var t=document.createElement("svg");t.setAttribute("xmlns","http://www.w3.org/2000/svg");t.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink");for(var i=0;i<e.processing.buffer.length;i++){var o=document.createElement("g"),r=e.processing.buffer[i];r[0].setAttribute("xmlns","http://www.w3.org/2000/svg");r[0].setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink");o.setAttribute("transform","translate("+r[1].x+","+r[1].y+")");o.appendChild(r[0]);t.appendChild(o)}return(new XMLSerializer).serializeToString(t)},generateOutput:function(e,t){var i=this,o=[],r=[],n=document.createElement("canvas"),a=n.getContext("2d"),l={y:0,x:0},o=i.chart.div.getElementsByTagName("svg");for(var s=0;s<o.length;s++)r.push(o[s]);if(i.chart.legend&&i.chart.legend.position=="outside"){i.chart.legend.container.container.externalLegend=true;r.push(i.chart.legend.container.container);if(i.cfg.legendPosition=="left"){l.x=i.chart.legend.div.offsetWidth}else if(i.cfg.legendPosition=="top"){l.y=i.chart.legend.div.offsetHeight}else if(typeof i.cfg.legendPosition=="object"){l.y=i.cfg.legendPosition.chartTop;l.x=i.cfg.legendPosition.chartLeft}}i.processing.buffer=[];i.processing.drawn=0;i.canvas=n;i.svgs=[];if(i.DEBUG==10){i.log("START EXPORT")}if(i.DEBUG==10){i.log("START BUFFERING")}for(var s=0;s<r.length;s++){var g=r[s].parentNode,u=Number(g.style.left.slice(0,-2)),f=Number(g.style.top.slice(0,-2)),d=i.polifySVG(r[s].cloneNode(true)),c=AmCharts.extend({},l);if(r[s].externalLegend){if(i.cfg.legendPosition=="right"){l.y=0;l.x=i.chart.divRealWidth}else if(i.cfg.legendPosition=="bottom"){l.y=f?f:l.y}else if(typeof i.cfg.legendPosition=="object"){l.x=i.cfg.legendPosition.left;l.y=i.cfg.legendPosition.top}else{l.x=0;l.y=0}}else{if(g.style.position=="relative"){l.x=u?u:l.x;l.y=f?f:l.y}else{l.x=u;l.y=f}}i.processing.buffer.push([d,AmCharts.extend({},l)]);if(f&&u){l=c}else{l.y+=f?0:g.offsetHeight}if(i.DEBUG==10){i.log("BUFFERED",r[s],l)}}if(i.DEBUG==10){i.log("END BUFFERING")}if(i.DEBUG==10){i.log("START DRAWING",e.render)}if(i.DEBUG==10){i.log("FILL BACKGROUND")}n.id=AmCharts.getUniqueId();n.width=i.chart.divRealWidth;n.height=i.chart.divRealHeight;if(i.chart.legend&&i.chart.legend.position=="outside"){if(["left","right"].indexOf(i.cfg.legendPosition)!=-1){n.width+=i.chart.legend.div.offsetWidth}else if(typeof i.cfg.legendPosition=="object"){n.width+=i.cfg.legendPosition.width;n.height+=i.cfg.legendPosition.height}else{n.height+=i.chart.legend.div.offsetHeight}}var p={width:false,height:false};if(i.chart.periodSelector){if(["left","right"].indexOf(i.chart.periodSelector.position)!=-1){n.width-=i.chart.periodSelector.div.offsetWidth+16;p.width=true}else{n.height-=i.chart.periodSelector.div.offsetHeight;p.height=true}}if(i.chart.dataSetSelector){if(["left","right"].indexOf(i.chart.dataSetSelector.position)!=-1){if(!p.width){n.width-=i.chart.dataSetSelector.div.offsetWidth+16}}else{n.height-=i.chart.dataSetSelector.div.offsetHeight}}if(e.backgroundColor||e.format=="image/jpeg"){a.fillStyle=e.backgroundColor||"#FFFFFF";a.fillRect(0,0,n.width,n.height)}function m(){var o,r,l,s;if(i.processing.buffer.length==i.processing.drawn||e.format=="svg"){if(i.DEBUG==10){i.log("END DRAWING")}return t()}else{if(i.DEBUG==10){i.log("DRAW",i.processing.drawn+1,"OF",i.processing.buffer.length)}r=i.processing.buffer[i.processing.drawn];s=(new XMLSerializer).serializeToString(r[0]);l=r[1];if(i.DEBUG==10){i.log("SOURCE",s)}if(e.render=="browser"){o=new Image;o.id=AmCharts.getUniqueId();s="data:image/svg+xml;base64,"+btoa(s);o.onload=function(){a.drawImage(this,r[1].x,r[1].y);i.processing.drawn++;if(i.DEBUG==10){i.log("ONLOAD",this)}m()};o.onerror=function(){if(i.DEBUG==10){i.log("ONERROR",this)}a.drawImage(this,r[1].x,r[1].y);i.processing.drawn++;m()};o.src=s;if(i.DEBUG==10){i.log("ADD",o)}if(o.complete||typeof o.complete=="undefined"||o.complete===undefined){if(i.DEBUG==10){i.log("FORCE ONLOAD",o)}o.src="";o.src=s}}else if(e.render=="canvg"){canvg(n,s,{offsetX:l.x,offsetY:l.y,ignoreMouse:true,ignoreAnimation:true,ignoreDimensions:true,ignoreClear:true,renderCallback:function(){i.processing.drawn++;m()}})}}}return m()},generateButtons:function(){var e=this,t=0;if(e.div){div=e.div;div.innerHTML=""}else{div=document.createElement("div"),e.div=div}function i(o){var r=document.createElement("ul");r.setAttribute("style","list-style: none; margin: 0; padding: 0;");for(var n=0;n<o.length;n++){var a=document.createElement("li"),l=document.createElement("img"),s=document.createElement("a"),g=o[n],u=null,f=AmCharts.extend(AmCharts.extend({},e.cfg.menuItemStyle),o[n]);g=AmCharts.extend(AmCharts.extend({},e.cfg.menuItemOutput),g);if(g["icon"]){l.alt="";l.src=g["icon"];l.setAttribute("style","margin: 0 auto;border: none;outline: none");if(g["iconTitle"]){l.title=g["iconTitle"]}s.appendChild(l)}s.href="#";if(g["title"]){l.setAttribute("style","margin: 0px 5px;");s.innerHTML+=g.title}s.setAttribute("style","display: block;");AmCharts.extend(s.style,f);s.onclick=g.onclick.bind(s,e,g);a.appendChild(s);if(g.items){u=i(g.items);a.appendChild(u);a.onmouseover=function(){u.style.display="block"};a.onmouseout=function(){u.style.display="none"};u.style.display="none"}r.appendChild(a);s.onmouseover=function(){this.style.backgroundColor=f.rollOverBackgroundColor;this.style.color=f.rollOverColor;this.style.borderColor=f.rollOverBorderColor};s.onmouseout=function(){this.style.backgroundColor=f.backgroundColor;this.style.color=f.color;this.style.borderColor=f.borderColor}}t++;if(e.DEBUG==10){e.log("MENU",r)}return r}div.setAttribute("style","position: absolute;top:"+e.cfg.menuTop+";right:"+e.cfg.menuRight+";bottom:"+e.cfg.menuBottom+";left:"+e.cfg.menuLeft+";");div.setAttribute("class","amExportButton");div.appendChild(i(e.cfg.menuItems));e.chart.containerDiv.appendChild(div)}});
//# sourceMappingURL=amexport.map.js